//#pragma once
#include<iostream>
#include<functional>
#include<vector>
#include<stdlib.h>
#include<unistd.h>

using task_t=std::function<void()>;

class Tasks{
public:
	Tasks(){
		_tasks.push_back([](){std::cout<<"任务1...执行中...完毕\n";});
		_tasks.push_back([](){std::cout<<"任务2...执行中...完毕\n";});
		_tasks.push_back([](){std::cout<<"任务3...执行中...完毕\n";});
		_tasks.push_back([](){std::cout<<"任务4...执行中...完毕\n";});
		_tasks.push_back([](){std::cout<<"任务5...执行中...完毕\n";});
	}

	int Select(){
		return rand()%_tasks.size();
	}

	void Excute(long unsigned int num){
		if(num<0||num>=_tasks.size())
			return;
		
		_tasks[num]();
	}

	~ Tasks(){}
private:
	std::vector<task_t> _tasks;
};

Tasks tasks;

void ReadAndWork(){
	while(true){
		int num=0;
		ssize_t r=::read(0,&num,sizeof(num));
		if(r==sizeof(num)){
			tasks.Excute(num);

		}
		else if(r==0){
			std::cout<<"Child was successfully closed"<<std::endl;
			return;
		}
		else{}
	}
}